﻿Imports MySql.Data.MySqlClient

Public Class Utility

    Public Shared Function FormatSqlDecimal(ByVal inValue As Decimal) As String
        Try
            Return CStr(inValue).Replace(",", ".")
        Catch ex As Exception
            Return ""
        End Try
    End Function

    Public Shared Function ConvStrNum(ByVal inString As String) As Decimal
        Try
            If IsNumeric(inString) Then
                Return inString.Replace(".", ",")
            Else
                Return 0
            End If

        Catch ex As Exception
            Return 0
        End Try
    End Function

    Public Shared Function FormatSqlDate(ByVal inDate As String) As String
        Try
            If IsDate(inDate) Then
                If CDate(inDate).Year.ToString <> Mid(inDate, 1, 4) Then
                    Dim dData As DateTime = CType(inDate, DateTime)
                    Return String.Format("{0}/{1}/{2}", dData.Year.ToString, dData.Month.ToString, dData.Day.ToString)
                Else
                    Return inDate
                End If
            Else
                Return ""
            End If

        Catch ex As Exception
            Return ""
        End Try
    End Function

    Public Shared Sub ConvertImage(ByVal Filename As String, ByVal DesiredFormat As System.Drawing.Imaging.ImageFormat, ByVal NewFilename As String)
        ' Takes a filename and saves the file in a new format
        Try
            Dim imgFile As System.Drawing.Image = System.Drawing.Image.FromFile(Filename)
            imgFile.Save(NewFilename, DesiredFormat)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

End Class
